package bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 使用jsr-250规范
 */
@Component
public class Dog implements ApplicationContextAware {
    private ApplicationContext applicationContext;

    public Dog() {
        System.out.println("dog construct...");
    }

    /**
     * 构造器初始化并赋值之后调用
     */
    @PostConstruct
    public void postConstruct() {
        System.out.println("dog post construct...");
    }

    /**
     * IOC容器在销毁对象之前调用
     */
    @PreDestroy
    public void preDestroy() {
        System.out.println("dog pre-destroy...");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
